package com.tianyadu.security.service.impl;

import com.tianyadu.security.domain.UserInfo;
import com.tianyadu.security.repository.UserInfoRepostory;
import com.tianyadu.security.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @FileName: UserServiceImpl
 * @Description:
 * @author: xueyj
 * @create: 2018-11-26 18:53
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoRepostory repostory;

    /**
     * @Description: 新增用户
     * @param:
     * @return:
     * @author:
     * @date:   2018/12/4 18:11
     */
    @Override
    public UserInfo saveUserInfo(UserInfo userInfo) {
        return repostory.save(userInfo);
    }

    /**
     * @Description: 根据用户id删除用户信息
     * @param:
     * @return:
     * @author:
     * @date:   2018/12/5 14:36
     */
    @Override
    public void deleteUserById(String id) {
        repostory.deleteById(id);
    }

    /**
     * @Description: 根据id修改用户信息
     * @param:
     * @return:
     * @author:
     * @date:   2018/12/5 14:41
     */
    @Override
    public UserInfo updateUserInfo(UserInfo userInfo) {
        return repostory.save(userInfo);
    }

    /**
     * 通过openid来查询用户信息
     *
     * @param openid
     * @return
     */
    @Override
    public UserInfo findByOpenid(String openid) {
        return repostory.findByOpenid(openid);
    }

    /**
      * @Description: 查找全部用户
      * @param:
      * @return:
      * @author:
      * @date:   2018/12/4 16:04
      */
    @Override
    public List<UserInfo> findAll() {
        return repostory.findAll();
    }

    /**
      * @Description: 根据用户id查询用户信息
      * @param:
      * @return:
      * @author:
      * @date:   2018/12/4 16:50
      */
    @Override
    public UserInfo findById(String id) {
        return repostory.getOne(id);
    }


}